package Exception;

import java.io.FileNotFoundException;
import java.io.IOException;


public class Exception2 {
    public static void main(String[] args) throws FileNotFoundException ,IOException{
        readFile("c:\\a.txt");
        //路径无问题，读取文件
        readFile("c:\\a.jpg");
        readFile("d:\\a.txt");
        //传递的文件不是c:\a.txt
    }
        public static void readFile (String filename)throws FileNotFoundException,IOException
                //注意是备注在参数列表后面
        {
            if(!filename.equals("c:\\a.txt"))
            {
                throw new FileNotFoundException("传递的文件不是c:\\a.txt");
            }
            if(!filename.endsWith(".txt"))
            {
                throw new IOException("文件后缀不对");
            }
            System.out.println("路径无问题，读取文件");
        }
}
